import Vue from 'vue';
import moment from 'moment';
Vue.filter('dateFormat', function(value, format) {
  return value ? moment(value).format(format || 'YYYY-MM-DD , hh:mm:ss a') : '';
})
Vue.filter('formatMoney', function(value, symbol, decimal) {
  let str = (symbol || '￥') + ' ';
  if (value && !isNaN(value)) {
    let temp = Number(value).toFixed(decimal || 2);
    var b = temp.split(".");
    var x = b[0];
    var y = b[1];
    return str + (x || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') + '.' + y;
  } else {
    return str + '0.00'
  }
})

Vue.filter('formatMoneyPenny', function(value, symbol, decimal) {
  let str = (symbol || '￥') + ' ';
  if (value && !isNaN(value)) {
    let temp = (Number(value)/100).toFixed(decimal || 2);
    var b = temp.split(".");
    var x = b[0];
    var y = b[1];
    return str + (x || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') + '.' + y;
  } else {
    return str + '0.00'
  }
})

export function formatMoneyPenny(value, symbol, decimal) {
    let str = (symbol || '￥') + ' ';
  if (value && !isNaN(value)) {
    let temp = (Number(value)/100).toFixed(decimal || 2);
    var b = temp.split(".");
    var x = b[0];
    var y = b[1];
    return str + (x || 0).toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,') + '.' + y;
  } else {
    return str + '0.00'
  }
}

import { UserService } from './api';
export function getUserInfo(code) {
  return  UserService.findWxUserInfo(code)
}


Vue.directive('carplate', function(el, binding) {
  let args = binding.value;
  let colrs = {
    background: '',
    border: '',
    font: ''
  };
  let vehNo = '';
  if (args[1]) {
    switch (args[1]) {
// Integer 0：白，1：黄，2:蓝，3：黑，4：绿，9：其他颜色
      case 0:
      case "0":
        //白牌黑字
        colrs.background = '#fff';
        colrs.border = '#000000';
        colrs.font = '#000000';
        break;
      case 1:
      case "1":
        //黄牌黑字
        colrs.background = '#ffc107';
        colrs.border = '#e7f3fb';
        colrs.font = '#000000';
        break;

      case 2:
      case "2":
        //蓝牌白字
        colrs.background = '#1842ae';
        colrs.border = '#e7f3fb';
        colrs.font = '#e7f3fb';
        break; 
      case 3:
      case "3":
        //黑牌白字
        colrs.background = '#000000';
        colrs.border = '#fff';
        colrs.font = '#fff';
        break;

      case 4:
      case "4":
        //绿牌白字
        colrs.background = '#028a62';
        colrs.border = '#7ce1c1';
        colrs.font = '#e7f3fb';
        break;

      default:
              //蓝牌白字
        colrs.background = '#1842ae';
        colrs.border = '#e7f3fb';
        colrs.font = '#e7f3fb';
        break;

    }
  }
  if (args[0]) {
    vehNo = args[0].replace(new RegExp("\"|'", 'g'), "");
  }
  el.innerHTML = `
	<span style="background: ${colrs.background};min-width: 135px;height: 33px;display: inline-block;text-align: center;">
		<span style="border: 1px solid ${colrs.border};color: ${colrs.font};min-width: 94%;height: 80%;display: inline-block;margin: 3px; font-size: 23px;border-radius: 2px;">
  			${vehNo}
		</span>
	</span>`
})

Vue.directive('carplateText', function(el, binding) {
  let args = binding.value;
  let color = '#1842ae';
  let vehNo = '';
  if (args[1]) {
    switch (args[1]) {
      case 0:
      case "0":
        //白牌黑字
        color = '#bdbdbd';
        break;
      case 1:
      case "1":
      //黄牌黑字
        color = '#ffc107';    
        break;
      case 2:
      case "2":
        //蓝牌白字
        color = '#1842ae';
        break;
         case 3:
      case "3":
        //黑牌白字
        color = '#000000';
        break;
        break;
         case 4:
      case "4":
        //绿牌白字
        color = '#028a62';      
      default:
              //蓝牌白字
        color = '#1842ae';
        break;
    }
  }
  if (args[0]) {
    vehNo = args[0].replace(new RegExp("\"|'", 'g'), "");
  }
  el.innerHTML = `<span style='color:${color} ;font-weight: bold;font-size: 18px'>${vehNo}</span>`;
})
